import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.ImageIcon;


public class Enemy extends Entity
{

	public Enemy(int x, int y)
	{
		super(x, y);
	}
	
	public void update()
	{
		y += 1;
		checkCollisions();
	}
	
	public void draw(Graphics2D g2)
	{
		g2.drawImage(getEnemyImg(), x, y, null);
		//g2.draw(getBounds());
	}
	
	public Image getEnemyImg()
	{
		ImageIcon ic = new ImageIcon("EnemyShip.png");
		return ic.getImage();
	}
	
	public Rectangle getBounds()
	{
		return new Rectangle(x, y, getEnemyImg().getWidth(null),getEnemyImg().getHeight(null));
	}
	
	public void checkCollisions()
	{
		ArrayList<Bullet> bullets = Draw.getBulletList();
		
		for (int i = 0; i < bullets.size(); i++)
		{
			Bullet tempBullet = bullets.get(i);
			if (getBounds().intersects(tempBullet.getBounds()))
			{
				Draw.removeEnemy(this);
				Draw.removeBullet(tempBullet);
			}
		}
	}
}
